package com.ebring.shareEducation.service.impl;

import com.ebring.shareEducation.bean.Institution;
import com.ebring.shareEducation.bean.Traderecords;
import com.ebring.shareEducation.bean.User;
import com.ebring.shareEducation.bean.UserRole;
import com.ebring.shareEducation.bean.response.UserRsp;
import com.ebring.shareEducation.dao.*;
import com.ebring.shareEducation.service.TraderecordsService;
import com.ebring.shareEducation.service.UserService;
import com.ebring.shareEducation.utils.JwtUtils;
import com.ebring.shareEducation.utils.Md5Utils;
import com.ebring.shareEducation.utils.RspMsg;
import com.ebring.shareEducation.utils.UuidUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Transactional
public class TraderecordsServiceImpl implements TraderecordsService {


    @Autowired
    private TraderecordsMapper traderecordsMapper;


    @Override
    public RspMsg<Traderecords> insertTrade(Traderecords traderecords) {
        return null;
    }

    @Override
    public RspMsg<Traderecords> updateTrade(Traderecords traderecords) {
        return null;
    }

    @Override
    public RspMsg<Traderecords> selectTradeById(String id) {
        Traderecords tra=new Traderecords();
        RspMsg rspMsg = new RspMsg();
        List<Traderecords> tradeList = traderecordsMapper.findTradeById(tra.setId(id));
        if (tradeList.isEmpty() || tradeList == null) {
            rspMsg.setOK();
            rspMsg.setMsg("未找到相关数据");
            return rspMsg;
        }
        rspMsg.setOK();
        rspMsg.setResult(tradeList);
        return rspMsg;
    }

    @Override
    public RspMsg<Traderecords> DeleteTrade(String[] Id) {
        return null;
    }

    @Override
    public RspMsg<Traderecords> selectTradefind() {
        RspMsg rspMsg = new RspMsg();
        Map<String, Object> map = new LinkedHashMap<>();
        List<Traderecords> tradeList = traderecordsMapper.findTradeAll();
        if (tradeList.isEmpty() || tradeList == null) {
            rspMsg.setOK();
            rspMsg.setMsg("未找到相关数据");
            return rspMsg;
        }
        PageInfo<Traderecords> pageInfo = new PageInfo<Traderecords>(tradeList);
        // 总条数
        map.put("total", pageInfo.getTotal());
        // 每页显示条数
        map.put("curPage", pageInfo.getPageSize());
        // 总页数
        map.put("pages", pageInfo.getPages());
        // 当前页
        map.put("pageNum", pageInfo.getPageNum());
        map.put("tradeList", tradeList);
        rspMsg.setOK();
        rspMsg.setResult(map);
        return rspMsg;
    }
    @Override
    public RspMsg<List<Traderecords>> findTrade(Traderecords traderecords) {
        RspMsg rspMsg = new RspMsg();
        Map<String, Object> map = new LinkedHashMap<>();
        List<Traderecords> tradeList = traderecordsMapper.findTradeById(traderecords);
        if (tradeList.isEmpty() || tradeList == null) {
            rspMsg.setOK();
            rspMsg.setMsg("未找到相关订单");
            return rspMsg;
        }

        PageInfo<Traderecords> pageInfo = new PageInfo<>(tradeList);

        // 总条数
        map.put("total", pageInfo.getTotal());
        // 每页显示条数
        map.put("curPage", pageInfo.getPageSize());
        // 总页数
        map.put("pages", pageInfo.getPages());
        // 当前页
        map.put("pageNum", pageInfo.getPageNum());
        map.put("tradeList", tradeList);
        rspMsg.setOK();
        rspMsg.setResult(map);
        return rspMsg;
    }
}
